package com.bpf.base.service.system;

import javax.annotation.Resource;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.bpf.base.util.MapUtil;
import com.bpf.base.dao.system.TSysRole2menuDao;
import com.bpf.base.model.system.Role2MenuKey;

/**
 * TODO 本代码由代码生成工具生成
 * @date 2016-07-19 05:31:26
 */
@Service
public class TSysRole2menuService{

	private Logger logger = LoggerFactory.getLogger(TSysRole2menuService.class);
     
    @Resource
	private TSysRole2menuDao tSysRole2menuDao;
	
	//根据条件搜索记录
	public Map<String , Object> getTSysRole2menuList(Map<String, Object> params){
		Map<String , Object> queryMap = new HashMap<String, Object>();
		Map<String , Object> resultMap = new HashMap<String, Object>();
		//TODO 根据需要封装查询需要的条件
		queryMap.putAll(params);
		resultMap.put("rows", tSysRole2menuDao.selectList(queryMap));
		resultMap.put("total", tSysRole2menuDao.selectCount(queryMap));
		return resultMap;
	}
       
	//新增记录
	public int addTSysRole2menu(Map<String, Object> params){
		try {
			//TODO 根据需要封装查询需要的条件
			Role2MenuKey temp=MapUtil.toObject(Role2MenuKey.class, params);
			return tSysRole2menuDao.insert(temp);
		} catch (Exception e) {
			logger.error("添加失败",e);
			return -1;
		}
	}
	
	//更新记录
	public int updateTSysRole2menu(Role2MenuKey role2MenuKey){
		return tSysRole2menuDao.update(role2MenuKey);
	}
	
	//删除记录
	public int delTSysRole2menu(Map<String, Object> params){
		return tSysRole2menuDao.deleteByMap(params);
	}
	
	//根据主键批量删除
	public int delTSysRole2menuBat(String[] idArray){
		for(String pk:idArray){
			tSysRole2menuDao.deleteByPk(pk);
		}
		return idArray.length;
	}
	
	public List<Role2MenuKey> getAllTSysRole2menu(Map<String, Object> params){
		return tSysRole2menuDao.selectList(params);
	}
	
}
